package top.iridescent.gateway.job;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.iridescent.gateway.common.Constant;
import top.iridescent.gateway.entity.GatewayLogCfg;
import top.iridescent.gateway.service.GatewayLogCfgService;

import java.util.List;

@Component
@Slf4j
public class InitUrlType {
    @Autowired
    private GatewayLogCfgService logCfgService;

    /**
     * 定时查询gateway配置的需要记录日志的url
     */
    @Scheduled(cron = "0 */3 * * * *")
    public void init(){
        log.info("======start load log_url ========!");
        List<GatewayLogCfg> list=  logCfgService.getEnableUrl();
        if (!list.isEmpty()){
         list.forEach(e-> Constant.ENABLE_LOG_URL.add(e.getUrl()));
        }
        log.info("======end load log_url ========!");
    }
}
